import 'package:flutter/material.dart';
import 'package:flutter_enjoy/pagess/home/home.dart';
import 'package:flutter_enjoy/pagess/mine/index.dart';

class TabsPage extends StatefulWidget {
  const TabsPage({super.key});

  @override
  // ignore: library_private_types_in_public_api
  _TabsPageState createState() => _TabsPageState();
}

class _TabsPageState extends State<TabsPage> {
  int _currentIndex = 0;
  List tabList = [
    {
      'title': '首页',
      'icon': 'assets/tabs/home_default.png',
      'activeIcon': 'assets/tabs/home_active.png',
    },
    {
      'title': '我的',
      'icon': 'assets/tabs/my_default.png',
      'activeIcon': 'assets/tabs/my_active.png',
    },
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: [
          Container(
            child: const HomePage(),
          ),
          Container(
            child: const Mine(),
          ),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: tabList
            .map((item) => BottomNavigationBarItem(
                  icon: Image.asset(item['icon'], width: 24, height: 24),
                  activeIcon:
                      Image.asset(item['activeIcon'], width: 24, height: 24),
                  label: item['title'],
                ))
            .toList(),
        currentIndex: _currentIndex,
        onTap: (index) => setState(() => _currentIndex = index),
        type: BottomNavigationBarType.fixed,
        selectedItemColor: const Color(0xFF6490ac),
        unselectedItemColor: Colors.grey,
        selectedLabelStyle: const TextStyle(fontSize: 12),
        unselectedLabelStyle: const TextStyle(fontSize: 12),
      ),
    );
  }
}
